{extend name="common/block" /}

{block name="style"}
<style>
    .layui-table-cell{
        height:auto!important;
    }
</style>
{/block}
{block name="content"}
<div class="layui-btn-container " style="display: inline-block;">

</div>
<div class="j-right" style="height: 40px;">
    <input class="layui-input" id="edtSearch" value="" placeholder="输入搜索条件"
           style="display: inline-block;width: 140px;height: 30px;line-height: 30px;padding: 0 5px;margin-right: 5px;"/>
    <div class="layui-btn-container" style="display: inline-block;">
        <button id="btnSearch" class="layui-btn layui-btn-sm layui-btn-primary">
            <i class="layui-icon">&#xe615;</i>搜索
        </button>
        <button id="btnClearSearch" class="layui-btn layui-btn-sm layui-btn-primary">
            <i class="layui-icon">&#x1006;</i>清除搜索
        </button>
    </div>
</div>

<script type="text/html" id="opera">
    {{# if(d.is_install == 0){ }}
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="install">安装</a>
    {{# }else { }}
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="uninstall">卸载</a>
        {{# if(d.is_config == 1){ }}
        <a class="layui-btn layui-btn-warm layui-btn-xs " lay-event="config">配置</a>
        {{# } }}
    {{# } }}
</script>

<table id="table" lay-filter="Plugin"></table>
{/block}

{block name="script"}
<script>
    layui.use(['table', 'layer', 'jquery'], function () {
        var table = layui.table
            , layer = layui.layer
            , $ = layui.jquery;

        table.render({
            elem: '#table',
            url: '{:url("index")}',
            page: true,
            height: 'full-200',
            toolbar: true,
            method:'post',
            cols: [[ //表头
                {type:'checkbox'}
                , {field:'name',title:'插件名称'}
                , {field:'icon',title:'插件图标',templet:function(d){
                    if(d.icon !== ''){
                        return '<div><img  width="100%" src="'+d.icon+'"/></div>';
                    }else{
                        return '';
                    }
                    }}
                , {field:'flag',title:'插件标识'}
                , {field:'author',title:'作者'}
                , {field:'descption',title:'描述'}
                , {title:'操作',templet:'#opera',width:150,align:'center'}
            ]],
        })
        
         table.on('tool(Plugin)', function(obj){
            var data = obj.data;
            if(obj.event === 'uninstall'){
                layer.confirm('确定卸载该插件？', function(index){
                    layer.close(index);
                    $.get('uninstall', {flag:data.flag},function(r){
                        if(r.code == 1){
                            layer.msg('插件已卸载');
                            setTimeout(function(){
                                window.location.reload();
                            },1500)
                        }else{
                            layer.msg(r.msg);
                        }
                    },'json')
                });
            } else if(obj.event === 'install'){
                $.get('install', {flag:data.flag},function(r){
                    if(r.code == 1){
                        layer.msg('插件安装成功');
                        setTimeout(function(){
                            window.location.reload();
                        },1500)
                    }else{
                        layer.msg(r.msg);
                    }
                },'json')
            }else if(obj.event == 'config'){
                layer.open({
                    type:2,
                    content:"{:url('Plugin/config')}?flag=" + data.flag,
                    shadeClose:true,
                    area:['80%','80%']
                })
            }
        });
})
</script>
{/block}
